package com.simons.common.utils.xml.xstream;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

import lombok.Getter;
import lombok.Setter;

/**
 * xml具体建造者

 * @Description:TODO

 * @author:JSM

 * @time:2018年3月30日 下午5:15:41
 */
@Getter
@Setter
public abstract class XmlConcreteBuilder implements XmlBuilder {


	public XStream xStream;
	
	public String xmlStr;
	
	private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
	
	@Override
	public void buildAttrXstream() {
		this.xStream = new XStream(new DomDriver());
	}
	
	@Override
	public void buildSimpleXstream() {
		this.xStream = new XStream();
	}

	@Override
	public void makeXmlFile(String targetPath) throws IOException {
		File file = new File(targetPath);
		String data = XML_HEADER + "\n" + this.xmlStr;
		FileUtils.writeByteArrayToFile(file, data.getBytes());
	}

}
